﻿<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" assembly="DataLayer" namespace="DataLayer.Entities">
  <class name="AlbumEntity" table="albums" lazy="false">
    <id name="ID" column="id">
      <generator class="native" />
    </id>
    <property name="Name" column="name" not-null="true"/>
    <property name="Description" column="description"/>
    <property name="PrivateMarks" column="private_marks"/>
    <property name="Label" column="label"/>
    <property name="ASIN" column="asin"/>
    <property name="FreedbID" column="freedb_id"/>
    <property name="Year" column="year"/>
    <property name="DiscsCount" column="discs_count"/>
    <property name="Rating" column="rating" not-null="true"/>

    <!--Owns relation and persistes bindings into albums_genres table-->
    <bag name="Genres" table="albums_genres" lazy="true">
      <key column="album_id"/>
      <many-to-many column="genre_id"
         class="DataLayer.Entities.GenreEntity, NHibernateManyToMany"/>
    </bag>

    <bag name="Tags" table="tags_albums" lazy="true">
      <key column="album_id"/>
      <many-to-many column="tag_id"
         class="DataLayer.Entities.TagEntity, NHibernateManyToMany"/>
    </bag>

    <bag name="Artists" table="artists_albums" lazy="true">
      <key column="album_id"/>
      <many-to-many column="artist_id"
         class="DataLayer.Entities.ArtistEntity, NHibernateManyToMany"/>
    </bag>
    
    <bag name="Tracks" cascade="all-delete-orphan" lazy="true">
      <key column="album_id" not-null="true"/>
      <one-to-many
         class="DataLayer.Entities.TrackEntity, NHibernateOneToMany"/>
    </bag>

    <bag name="Listens" cascade="all" lazy="true">
      <key column="album_id"/>
      <one-to-many
         class="DataLayer.Entities.ListeningEntity, NHibernateOneToMany"/>
    </bag>
  </class>
</hibernate-mapping>